package com.itheima.service.impl;

import com.itheima.dao.QrtzJobDetailsDao;
import com.itheima.pojo.QrtzJobDetails;
import com.itheima.service.QrtzJobDetailsService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * (QrtzJobDetails)表服务实现类
 *
 * @author makejava
 * @since 2022-01-16 15:48:52
 */
@Service("qrtzJobDetailsService")
public class QrtzJobDetailsServiceImpl implements QrtzJobDetailsService {
    @Resource
    private QrtzJobDetailsDao qrtzJobDetailsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param schedName 主键
     * @return 实例对象
     */
    @Override
    public QrtzJobDetails queryById(String schedName) {
        return this.qrtzJobDetailsDao.queryById(schedName);
    }

    /**
     * 分页查询
     *
     * @param qrtzJobDetails 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<QrtzJobDetails> queryByPage(QrtzJobDetails qrtzJobDetails, PageRequest pageRequest) {
        long total = this.qrtzJobDetailsDao.count(qrtzJobDetails);
        return new PageImpl<>(this.qrtzJobDetailsDao.queryAllByLimit(qrtzJobDetails, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param qrtzJobDetails 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzJobDetails insert(QrtzJobDetails qrtzJobDetails) {
        this.qrtzJobDetailsDao.insert(qrtzJobDetails);
        return qrtzJobDetails;
    }

    /**
     * 修改数据
     *
     * @param qrtzJobDetails 实例对象
     * @return 实例对象
     */
    @Override
    public QrtzJobDetails update(QrtzJobDetails qrtzJobDetails) {
        this.qrtzJobDetailsDao.update(qrtzJobDetails);
        return this.queryById(qrtzJobDetails.getSchedName());
    }

    /**
     * 通过主键删除数据
     *
     * @param schedName 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String schedName) {
        return this.qrtzJobDetailsDao.deleteById(schedName) > 0;
    }
}
